/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pruebarepositorios.Logica;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;

/**
 *
 * @author CamiloRudas
 */
public class DaoPuntos {
    
    private String ruta;

    public DaoPuntos() {
        ruta= "Puntos.oe";
    }

    public String getRuta() {
        return ruta;
    }

    public void setRuta(String ruta) {
        this.ruta = ruta;
    }
    public void guardarPuntos(ArrayList<int[]> puntos) {
        try {
            BufferedWriter lapiz = new BufferedWriter(new FileWriter(ruta));
            lapiz.write("Listado de Puntos");
            lapiz.newLine();
            lapiz.write("=================");
            lapiz.newLine();
            int c = 1;
           for (int[] ds : puntos) {
             lapiz.write(c+") x: "+ds[0]+" y: "+ds[1]);
             lapiz.newLine();
             c++;
            }
            lapiz.flush();
            lapiz.close();
        } catch (Exception e) {
            System.out.println ("error guardado");
        }
    }

    public ArrayList<int[]> cargarPunto() {
        ArrayList<int[]> puntos = new ArrayList<int[]>();
        try {    
            BufferedReader r = new BufferedReader(new FileReader(new File(ruta)));
            r.readLine();
            r.readLine();
            while(r.ready()){
                String linea = r.readLine();
                int x = Integer.parseInt(linea.split(" ")[2]);
                int y = Integer.parseInt(linea.split(" ")[4]);
                int nuevo[] = {x,y};
                puntos.add(nuevo);
            }
            r.close();
        } catch (Exception ex) {
            System.out.println ("error lectura");
        }
        return puntos;
    }
}
